using System;
using FireStarterModeller.BO;
using Habanero.BO;
using Habanero.Test.Structure;
using NUnit.Framework;
using Rhino.Mocks;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for GenerationSettings objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for GenerationSettings.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestGenerationSettings
    {
        [SetUp]
        public override void SetupTest()
        {
            //Runs every time that any testmethod is executed
            base.SetupTest();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [TearDown]
        public override void TearDownTest()
        {
            //runs every time any testmethod is complete
            base.TearDownTest();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            GenerationSettings generationSettings = TestUtilsGenerationSettings.CreateUnsavedValidGenerationSettings();
            //---------------Assert Precondition----------------
            Assert.IsFalse(String.IsNullOrEmpty(generationSettings.SolutionName), "ProjectName Should not be null");
            //---------------Execute Test ----------------------
            string actualToString = generationSettings.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(generationSettings.SolutionName, actualToString);
        }

        [Test]
        public void Test_CodeGenerationController_GetAndSet()
        {
            //---------------Set up test pack-------------------
            GenerationSettings generationSettings = new GenerationSettings();
            ICodeGenerationController codeGenerationController = MockRepository.GenerateStub<ICodeGenerationController>();
            //---------------Assert Precondition----------------
            Assert.IsNull(generationSettings.CodeGenerationController);
            //---------------Execute Test ----------------------
            generationSettings.CodeGenerationController = codeGenerationController;
            //---------------Test Result -----------------------
            Assert.AreSame(codeGenerationController, generationSettings.CodeGenerationController);
        }

        [Test]
        public void Test_SolutionName_WhenSolutonNull_ShouldReturnEmpty()
        {
            //---------------Set up test pack-------------------
            var generationSettings = new GenerationSettings();
            //---------------Assert Precondition----------------
            Assert.IsNull(generationSettings.Solution);
            //---------------Execute Test ----------------------
            string solutionName = generationSettings.SolutionName;
            //---------------Test Result -----------------------
            Assert.IsNullOrEmpty(solutionName);
        }
        [Test]
        public void Test_SolutionName_WhenNotSolutonNull_ShouldReturnSolutonName()
        {
            //---------------Set up test pack-------------------
            var generationSettings = new GenerationSettings();
            generationSettings.Solution = new DMSolution(GetRandomString());
            //---------------Assert Precondition----------------
            Assert.IsNotNull(generationSettings.Solution);
            Assert.IsNotNullOrEmpty(generationSettings.Solution.SolutionName);
            //---------------Execute Test ----------------------
            string solutionName = generationSettings.SolutionName;
            //---------------Test Result -----------------------
            Assert.AreEqual(generationSettings.Solution.SolutionName, solutionName);
        }
        [Test]
        public void Test_SetSolutionName_WhenSolutonNull_ShouldNotSetSolutionName()
        {
            //---------------Set up test pack-------------------
            var generationSettings = new GenerationSettings();
            //---------------Assert Precondition----------------
            Assert.IsNull(generationSettings.Solution);
            //---------------Execute Test ----------------------
            generationSettings.SolutionName = GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsNullOrEmpty(generationSettings.SolutionName);
        }
        [Test]
        public void Test_SetSolutionName_WhenNotSolutonNull_ShouldSetSolutonName()
        {
            //---------------Set up test pack-------------------
            var generationSettings = new GenerationSettings();
            generationSettings.Solution = new DMSolution(GetRandomString());
            //---------------Assert Precondition----------------
            Assert.IsNotNull(generationSettings.Solution);
            Assert.IsNotNullOrEmpty(generationSettings.Solution.SolutionName);
            //---------------Execute Test ----------------------
            string expectedSolutionName = GetRandomString();
            generationSettings.SolutionName = expectedSolutionName;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedSolutionName, generationSettings.Solution.SolutionName);
            Assert.AreEqual(expectedSolutionName, generationSettings.SolutionName);
        }

        private string GetRandomString()
        {
            return RandomValueGen.GetRandomString();
        }
    }

    
}